<?php
/**
 * Created by PhpStorm.
 * User: asdf
 * Date: 2021/9/18
 * Time: 23:48
 */

namespace core\lib;


use function core\p;

class MAPProter{
    public static $instance;
    public $ctl;
    public $action;
    public $forder;
    public static $uri = null;
    public static $patharr = [];


    /**
     * 隐藏index
     * 获取参数
     * 返回控制器和方法
     */
    public function __construct($qurey_src)
    {
        self::$uri = $qurey_src;
            $this->loader();
            $this->getControler();
            $this->getAction();
            $this->getForder();
    }

    private function loader(){

        if (isset(self::$uri)&&self::$uri !="/" || self::$uri == "" ){
            self::$patharr = explode('/',trim(self::$uri,'/'));

            return true;
        }else{
            $this->forder = "index";
            $this->ctl='index';
            $this->action = 'index';
            return false;
        }
    }

    //多应用目录
    private function getForder(){
        //多应用目录
        if (isset(self::$patharr[0])){
            $this->forder = self::$patharr[0];
        }else{
            $this->forder = 'index';
        }
    }

    //控制器
    private function getControler(){
        //控制器
        if (isset(self::$patharr[1])){
            $this->ctl = self::$patharr[1];
        }else{
            $this->ctl = 'index';
        }
    }

    //操作
    private function getAction(){
        //操作
        if (isset(self::$patharr[2])){
            $this->action = self::$patharr[2];
        }else{
            $this->action = 'index';
        }
    }


    public static function Newinstance($qurey_src){
        if(!self::$instance instanceof self){
            self::$instance = new self($qurey_src);
        }
        return self::$instance;
    }

}